package com.ruoyi.web.controller.paymentSettings;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PaymentChannelSettings;
import com.ruoyi.system.service.IPaymentChannelSettingsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付通道设置Controller
 *
 * @author ruoyi
 * @date 2025-05-12
 */
@Api(tags="支付通道设置")
@RestController
@RequestMapping("/system/paymentChannelSettings")
public class PaymentChannelSettingsController extends BaseController
{
    @Autowired
    private IPaymentChannelSettingsService paymentChannelSettingsService;

    /**
     * 查询支付通道设置列表
     */
    @ApiOperation("查询支付通道设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();
        List<PaymentChannelSettings> list = paymentChannelSettingsService.selectPaymentChannelSettingsListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出支付通道设置列表
     */
    @ApiOperation("导出支付通道设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:export')")
    @Log(title = "支付通道设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String storeName)
    {
        List<PaymentChannelSettings> list = paymentChannelSettingsService.selectPaymentChannelSettingsListByName(storeName);
        ExcelUtil<PaymentChannelSettings> util = new ExcelUtil<PaymentChannelSettings>(PaymentChannelSettings.class);
        util.exportExcel(response, list, "支付通道设置数据");
    }

    /**
     * 获取支付通道设置详细信息
     */
    @ApiOperation("获取支付通道设置详细信息")
    @PreAuthorize("@ss.hasPermi('system:settings:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(paymentChannelSettingsService.selectPaymentChannelSettingsById(id));
    }

    /**
     * 新增支付通道设置
     */
    @ApiOperation("新增支付通道设置")
    @PreAuthorize("@ss.hasPermi('system:settings:add')")
    @Log(title = "支付通道设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaymentChannelSettings paymentChannelSettings)
    {
        return toAjax(paymentChannelSettingsService.insertPaymentChannelSettings(paymentChannelSettings));
    }

    /**
     * 修改支付通道设置
     */
    @ApiOperation("修改支付通道设置")
    @PreAuthorize("@ss.hasPermi('system:settings:edit')")
    @Log(title = "支付通道设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaymentChannelSettings paymentChannelSettings)
    {
        return toAjax(paymentChannelSettingsService.updatePaymentChannelSettings(paymentChannelSettings));
    }

    /**
     * 删除支付通道设置
     */
    @ApiOperation("删除支付通道设置")
    @PreAuthorize("@ss.hasPermi('system:settings:remove')")
    @Log(title = "支付通道设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(paymentChannelSettingsService.deletePaymentChannelSettingsByIds(ids));
    }
}
